package example

import (
	
	"github.com/flipped-aurora/gin-vue-admin/server/global"
    "github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
    "github.com/flipped-aurora/gin-vue-admin/server/model/example"
    exampleReq "github.com/flipped-aurora/gin-vue-admin/server/model/example/request"
    "github.com/gin-gonic/gin"
    "go.uber.org/zap"
)

type HeroApi struct {}



// CreateHero 创建英雄信息
// @Tags Hero
// @Summary 创建英雄信息
// @Security ApiKeyAuth
// @Accept application/json
// @Produce application/json
// @Param data body example.Hero true "创建英雄信息"
// @Success 200 {object} response.Response{msg=string} "创建成功"
// @Router /HR/createHero [post]
func (HRApi *HeroApi) CreateHero(c *gin.Context) {
	var HR example.Hero
	err := c.ShouldBindJSON(&HR)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	err = HRService.CreateHero(&HR)
	if err != nil {
        global.GVA_LOG.Error("创建失败!", zap.Error(err))
		response.FailWithMessage("创建失败:" + err.Error(), c)
		return
	}
    response.OkWithMessage("创建成功", c)
}

// DeleteHero 删除英雄信息
// @Tags Hero
// @Summary 删除英雄信息
// @Security ApiKeyAuth
// @Accept application/json
// @Produce application/json
// @Param data body example.Hero true "删除英雄信息"
// @Success 200 {object} response.Response{msg=string} "删除成功"
// @Router /HR/deleteHero [delete]
func (HRApi *HeroApi) DeleteHero(c *gin.Context) {
	ID := c.Query("ID")
	err := HRService.DeleteHero(ID)
	if err != nil {
        global.GVA_LOG.Error("删除失败!", zap.Error(err))
		response.FailWithMessage("删除失败:" + err.Error(), c)
		return
	}
	response.OkWithMessage("删除成功", c)
}

// DeleteHeroByIds 批量删除英雄信息
// @Tags Hero
// @Summary 批量删除英雄信息
// @Security ApiKeyAuth
// @Accept application/json
// @Produce application/json
// @Success 200 {object} response.Response{msg=string} "批量删除成功"
// @Router /HR/deleteHeroByIds [delete]
func (HRApi *HeroApi) DeleteHeroByIds(c *gin.Context) {
	IDs := c.QueryArray("IDs[]")
	err := HRService.DeleteHeroByIds(IDs)
	if err != nil {
        global.GVA_LOG.Error("批量删除失败!", zap.Error(err))
		response.FailWithMessage("批量删除失败:" + err.Error(), c)
		return
	}
	response.OkWithMessage("批量删除成功", c)
}

// UpdateHero 更新英雄信息
// @Tags Hero
// @Summary 更新英雄信息
// @Security ApiKeyAuth
// @Accept application/json
// @Produce application/json
// @Param data body example.Hero true "更新英雄信息"
// @Success 200 {object} response.Response{msg=string} "更新成功"
// @Router /HR/updateHero [put]
func (HRApi *HeroApi) UpdateHero(c *gin.Context) {
	var HR example.Hero
	err := c.ShouldBindJSON(&HR)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	err = HRService.UpdateHero(HR)
	if err != nil {
        global.GVA_LOG.Error("更新失败!", zap.Error(err))
		response.FailWithMessage("更新失败:" + err.Error(), c)
		return
	}
	response.OkWithMessage("更新成功", c)
}

// FindHero 用id查询英雄信息
// @Tags Hero
// @Summary 用id查询英雄信息
// @Security ApiKeyAuth
// @Accept application/json
// @Produce application/json
// @Param ID query uint true "用id查询英雄信息"
// @Success 200 {object} response.Response{data=example.Hero,msg=string} "查询成功"
// @Router /HR/findHero [get]
func (HRApi *HeroApi) FindHero(c *gin.Context) {
	ID := c.Query("ID")
	reHR, err := HRService.GetHero(ID)
	if err != nil {
        global.GVA_LOG.Error("查询失败!", zap.Error(err))
		response.FailWithMessage("查询失败:" + err.Error(), c)
		return
	}
	response.OkWithData(reHR, c)
}
// GetHeroList 分页获取英雄信息列表
// @Tags Hero
// @Summary 分页获取英雄信息列表
// @Security ApiKeyAuth
// @Accept application/json
// @Produce application/json
// @Param data query exampleReq.HeroSearch true "分页获取英雄信息列表"
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "获取成功"
// @Router /HR/getHeroList [get]
func (HRApi *HeroApi) GetHeroList(c *gin.Context) {
	var pageInfo exampleReq.HeroSearch
	err := c.ShouldBindQuery(&pageInfo)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	list, total, err := HRService.GetHeroInfoList(pageInfo)
	if err != nil {
	    global.GVA_LOG.Error("获取失败!", zap.Error(err))
        response.FailWithMessage("获取失败:" + err.Error(), c)
        return
    }
    response.OkWithDetailed(response.PageResult{
        List:     list,
        Total:    total,
        Page:     pageInfo.Page,
        PageSize: pageInfo.PageSize,
    }, "获取成功", c)
}

// GetHeroPublic 不需要鉴权的英雄信息接口
// @Tags Hero
// @Summary 不需要鉴权的英雄信息接口
// @Accept application/json
// @Produce application/json
// @Success 200 {object} response.Response{data=object,msg=string} "获取成功"
// @Router /HR/getHeroPublic [get]
func (HRApi *HeroApi) GetHeroPublic(c *gin.Context) {
    // 此接口不需要鉴权
    // 示例为返回了一个固定的消息接口，一般本接口用于C端服务，需要自己实现业务逻辑
    HRService.GetHeroPublic()
    response.OkWithDetailed(gin.H{
       "info": "不需要鉴权的英雄信息接口信息",
    }, "获取成功", c)
}
